package com.wheat.vipcard.bean;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 	* A data access object (DAO) providing persistence and search support for Business entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see com.wheat.vipcard.bean.Business
  * @author MyEclipse Persistence Tools 
 */

public class BusinessDAO extends BaseHibernateDAO  {
		 private static final Log log = LogFactory.getLog(BusinessDAO.class);
		//property constants
	public static final String BS_CONTENT = "bsContent";
	public static final String BS_NAME = "bsName";
	public static final String BS_ADDRESS = "bsAddress";
	public static final String BS_TELL = "bsTell";
	public static final String BS_LOGO = "bsLogo";
	public static final String BS_TASTE = "bsTaste";
	public static final String BS_CONSUME = "bsConsume";
	public static final String BS_ENVIRONMENTAL = "bsEnvironmental";
	public static final String BS_EFFECT = "bsEffect";
	public static final String BS_SERVE = "bsServe";
	public static final String IS_GOOD = "isGood";
	public static final String IS_BAD = "isBad";
	public static final String GREAD = "gread";
	public static final String BSDISTANCE_X = "bsdistanceX";
	public static final String BSDISTANCE_Y = "bsdistanceY";
	public static final String BS_IMAGE_SHOW = "bsImageShow";
	public static final String BS_TYPE = "bsType";



    
    public void save(Business transientInstance) {
        log.debug("saving Business instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Business persistentInstance) {
        log.debug("deleting Business instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Business findById( java.lang.Integer id) {
        log.debug("getting Business instance with id: " + id);
        try {
            Business instance = (Business) getSession()
                    .get("com.wheat.vipcard.bean.Business", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Business instance) {
        log.debug("finding Business instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.wheat.vipcard.bean.Business")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Business instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Business as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByBsContent(Object bsContent
	) {
		return findByProperty(BS_CONTENT, bsContent
		);
	}
	
	public List findByBsName(Object bsName
	) {
		return findByProperty(BS_NAME, bsName
		);
	}
	
	public List findByBsAddress(Object bsAddress
	) {
		return findByProperty(BS_ADDRESS, bsAddress
		);
	}
	
	public List findByBsTell(Object bsTell
	) {
		return findByProperty(BS_TELL, bsTell
		);
	}
	
	public List findByBsLogo(Object bsLogo
	) {
		return findByProperty(BS_LOGO, bsLogo
		);
	}
	
	public List findByBsTaste(Object bsTaste
	) {
		return findByProperty(BS_TASTE, bsTaste
		);
	}
	
	public List findByBsConsume(Object bsConsume
	) {
		return findByProperty(BS_CONSUME, bsConsume
		);
	}
	
	public List findByBsEnvironmental(Object bsEnvironmental
	) {
		return findByProperty(BS_ENVIRONMENTAL, bsEnvironmental
		);
	}
	
	public List findByBsEffect(Object bsEffect
	) {
		return findByProperty(BS_EFFECT, bsEffect
		);
	}
	
	public List findByBsServe(Object bsServe
	) {
		return findByProperty(BS_SERVE, bsServe
		);
	}
	
	public List findByIsGood(Object isGood
	) {
		return findByProperty(IS_GOOD, isGood
		);
	}
	
	public List findByIsBad(Object isBad
	) {
		return findByProperty(IS_BAD, isBad
		);
	}
	
	public List findByGread(Object gread
	) {
		return findByProperty(GREAD, gread
		);
	}
	
	public List findByBsdistanceX(Object bsdistanceX
	) {
		return findByProperty(BSDISTANCE_X, bsdistanceX
		);
	}
	
	public List findByBsdistanceY(Object bsdistanceY
	) {
		return findByProperty(BSDISTANCE_Y, bsdistanceY
		);
	}
	
	public List findByBsImageShow(Object bsImageShow
	) {
		return findByProperty(BS_IMAGE_SHOW, bsImageShow
		);
	}
	
	public List findByBsType(Object bsType
	) {
		return findByProperty(BS_TYPE, bsType
		);
	}
	

	public List findAll() {
		log.debug("finding all Business instances");
		try {
			String queryString = "from Business";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Business merge(Business detachedInstance) {
        log.debug("merging Business instance");
        try {
            Business result = (Business) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Business instance) {
        log.debug("attaching dirty Business instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Business instance) {
        log.debug("attaching clean Business instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}